#include<algorithm>  // magic head file may be a bug
#include <iostream>
#include<iomanip>
#include<vector>
using namespace std;
#define maxn 1000001
bool cmp(int p[], int q[])
{
	if (p[0] == q[0])
	{
		return p[1] > q[1];
	}
	else
	{
		return p[0] < q[0];
	}
}
int n;
int **a = new int*[maxn];


int main()
{
	int i, j,max1=0;
	cin >> n;
	vector<int> f(n, 1);
	for (i = 0; i < n; i++)
	{
		a[i] = new int[2];
		cin >> a[i][0] >> a[i][1];
	}
	sort(a,a + n, cmp);
	for(i=1;i<=n-1;i++)
		for (j = 0; j < i; j++)
		{
			if (a[i][1] > a[j][1])
            {
				f[i] = max(f[i], f[j] + 1);
            max1=max(max1,f[i]);
            }
		}
	cout <<max1 << endl;
}
